package cn.jsj.hzu.qm.facecloud.ciuser.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hzu.jsj.utils.BeanFactory;
import cn.jsj.hzu.qm.facecloud.ciuser.pojo.Cici;
import cn.jsj.hzu.qm.facecloud.ciuser.pojo.Ciuser;
import cn.jsj.hzu.qm.facecloud.ciuser.service.CiciService;
import cn.jsj.hzu.qm.facecloud.ciuser.service.CiuserService;

/**
 * Servlet implementation class CiciServlet
 */
public class CiciServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		CiciService ciciService = BeanFactory.getBean("ciciService");
		CiuserService ciuserService = BeanFactory.getBean("ciuserService");
		
		String sidString = request.getParameter("userid");
		String labidString = request.getParameter("labid");
		String infoString = request.getParameter("info");
		
		if (sidString == null || labidString == null) {
			return;
		}
		
		Ciuser ciuser = ciuserService.findCiuserBySid(sidString, false);
		//请求者的ip地址！
		String ciipString = request.getRemoteAddr();
		if (ciuser == null) {
			response.getWriter().write("{'state':'"+0+"'}");
			return;
		}
		int userid = ciuser.getId();
		int labid = Integer.parseInt(labidString);
		
		//初始化实体
		Cici cici = new Cici();
		cici.setUserid(userid);
		cici.setLabid(labid);
		cici.setCiinfo(infoString);
		cici.setCiip(ciipString);
		
		//自动判断签到和签退
		int i = ciciService.AutoCheckin(cici, labid);
		response.getWriter().write("{'state':'"+i+"'}");
		return;
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
